package com.zjk.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjk.Result;
import com.zjk.dto.SearchSpuDTO;
import com.zjk.dto.SpuDTO;
import com.zjk.pojo.SpuImagesEntity;
import com.zjk.pojo.SpuInfoDescEntity;
import com.zjk.pojo.SpuInfoEntity;
import com.zjk.search.SearchItem;
import com.zjk.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author: gfk
 * @create: 2022/10/21
 * @Description:
 * @FileName: SpuController
 * @History:
 * @自定义内容：
 */
@RestController
@RequestMapping("product/spu")
public class SpuController {
    @Autowired
    SpuService spuService;

    @PostMapping("/spulist/{pageNo}/{pageSize}")
    public Page<SpuInfoEntity> spuList(@PathVariable Integer pageNo,
                                       @PathVariable Integer pageSize,
                                       @RequestBody SearchSpuDTO searchMap
    ){

        return spuService.spuList(pageNo,pageSize,searchMap);
    }

    @GetMapping("selectSpuInfoDescById/{spuId}")
    public SpuInfoDescEntity selectSpuInfoDescById(@PathVariable Long spuId){
        return spuService.selectSpuInfoDescBySpuId(spuId);
    }

    @GetMapping("selectSpuImagesDescBySpuId/{spuId}")
    public List<SpuImagesEntity> selectSpuImagesDescBySpuId(@PathVariable Long spuId){
        return spuService.selectSpuImagesDescBySpuId(spuId);
    }

    @PostMapping("save")
    public Result save(@RequestBody SpuDTO spuDTO){
        return spuService.save(spuDTO);
    }

    @GetMapping("deleteBySpuId/{spuId}")
    public Result deleteBySpuId(@PathVariable Long spuId){
        return spuService.deleteBySpuId(spuId);
    }

    @PostMapping("findSearchItemList")
    public List<SearchItem> findSearchItemList(@RequestBody Map searchMap){
        return spuService.findSearchItemList(searchMap);
    }



}
